import { createCommonPage, COLUMN_WIDTH } from '@/utils/service.js'
import { dateFormat } from '/src/utils/date'

/* const a = [
  { key: 'EDITOR_AUDITING', value: '待主编审核' },
  { key: 'EDITOR_REJECTED', value: '主编审核未通过' },
  { key: 'ADMIN_AUDITING', value: '待管理端审核' },
  { key: 'ADMIN_REJECTED', value: '管理端审核未通过' },
  { key: 'POOLING', value: '已入池' },
]
 */
export const createColumns = (vm) => [
  {
    title: '',
    width: 34,
    align: 'center',
    type: 'selection',
  },
  {
    title: '序号',
    key: 'id',
    align: 'center',
    width: 80,
    render(h, params) {
      return <div>{(vm.formData.pageNo - 1) * vm.formData.pageSize + params.index + 1}</div>
    },
  },
  {
    title: '稿件标题',
    align: 'center',
    width: COLUMN_WIDTH + 300,
    render(h, params) {
      return <article-title info={params.row}></article-title>
    },
  },
  { title: '上传用户', key: 'createBy', align: 'center' },
  {
    title: '上传时间',
    align: 'center',
    sortable: 'custom',
    sortType: 'desc',
    render(h, params) {
      return <div>{dateFormat(params.row.createTime || '', 'YYYY.MM.DD HH:mm:ss')}</div>
    },
  },
  {
    title: '审核状态',
    align: 'center',
    render(h, params) {
      return (
        <div class={(params.row.state && params.row.state.key) || ''}>
          {(params.row.state && params.row.state.value) || ''}
        </div>
      )
    },
  },
  {
    title: '操作',
    align: 'center',
    render(h, params) {
      if (!vm.hasPermission('article/product/audit')) return ''

      if (params.row.state && params.row.state.key === 'EDITOR_AUDITING') {
        return (
          <icon-button
            icon="audit_active"
            title="审核"
            activated={false}
            nativeOnClick={() => {
              vm.handleAudit(params.row)
            }}
          ></icon-button>
        )
      } else {
        return ''
      }
    },
  },
]
